<script setup lang="ts">
import preview from "../preview/index.vue";
import { useRouter } from "vue-router";
import { reactive, ref } from "vue";
import type { FormInstance, FormRules } from "element-plus";

const router = useRouter();
let show = router.currentRoute?.value?.query?.id || "";
const formRef = ref();
const form = reactive({
  status: "",
  desc: ""
});
const rules = {
  status: [{ required: true, message: "请选择审批结果", trigger: "change" }],
  desc: [{ required: true, message: "请填写审批意见", trigger: "blur" }]
};
const submitForm = async (formEl: FormInstance | undefined) => {
  if (!formEl) return;
  await formEl.validate((valid, fields) => {
    if (valid) {
      router.push({
        name: "sponsorApproval"
      });
    } else {
      console.log("error submit!", fields);
    }
  });
};
const goBack = () => {
  router.push({
    name: "sponsorApproval"
  });
};

const resetForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return;
  formEl.resetFields();
  router.push({
    name: "sponsorApproval"
  });
};
import infoDes from "@/views/project/archives/components/infoDes.vue";
</script>

<template>
  <el-card :body-style="{ padding: '10px' }" class="m-[20px]">
    <template #header>
      <el-page-header @back="goBack">
        <template #content>
          <span class="mr-3 text-large font-600"> 杭州青青草公益服务中心 </span>
        </template>
      </el-page-header>
    </template>
    <div class="pl-[10px] headerTitle"><span></span>项目执行情况</div>
    <div class="p-[20px] pt-0">
      <infoDes />
    </div>
    <preview :show="true" />
    <div v-if="show" class="p-[20px]">
      <el-form :model="form" :rules="rules" ref="formRef">
        <el-form-item label="审批结果" class="w-[240px]" prop="status">
          <el-select v-model="form.status" placeholder="请选择审批结果">
            <el-option label="通过" value="pass"></el-option>
            <el-option label="拒绝" value="refuse"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审批意见" prop="desc" class="w-[500px]">
          <el-input
            type="textarea"
            v-model="form.desc"
            placeholder="请输入审批意见"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm(formRef)"
            >提交</el-button
          >
          <el-button @click="resetForm(formRef)">取消</el-button>
        </el-form-item>
      </el-form>
    </div>
  </el-card>
</template>

<style lang="scss" scoped>
.headerTitle {
  content: " ";
  position: relative;
  border-bottom: 1px solid #eee;
  line-height: 48px;
  span {
    width: 4px;
    height: 15px;
    background: #409eff;
    position: absolute;
    top: 50%;
    left: 0;
    transform: translate(0, -50%);
  }
}
</style>
